package com.css.zfzx.sjcj.modules.hddcActiveFault.repository;

import com.css.zfzx.sjcj.modules.hddcActiveFault.repository.entity.HddcActivefaultEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.*;

/**
 * @author zyb
 * @date 2020-11-30
 */
public interface HddcActivefaultRepository extends JpaRepository<HddcActivefaultEntity, String> {
    @Query(nativeQuery = true, value = "select * from hddc_activefault where project_name in :projectIds and is_valid='1'")
    List<HddcActivefaultEntity> queryByProjectId(List<String> projectIds);

    @Query(nativeQuery = true, value = "select * from hddc_activefault where task_name in :taskIds and is_valid='1'")
    List<HddcActivefaultEntity> queryByTaskId(List<String> taskIds);

    @Query(nativeQuery = true, value = "select * from hddc_activefault where create_user = :createID and province = :provinceName and city =:cityName and area =:areaName and is_valid='1'")
    List<HddcActivefaultEntity> queryHddcActivefaultsByCreateuser(String createID,String provinceName,String cityName,String areaName);

    @Query(nativeQuery = true, value = "select * from hddc_activefault where is_valid='1'")
    List<HddcActivefaultEntity> findAll();

    @Modifying
    @Query(nativeQuery = true, value = "update hddc_activefault set is_valid='0', update_user =:uuser, update_time =:deletedate " +
            " where province = :provinceName and city =:cityName and area =:areaName and extends8 = :fileName ")
    void deleteFileData(String provinceName,String cityName,String areaName,String fileName,String uuser,Date deletedate);

    //select count(*) from hddc_activefault
    @Query(nativeQuery = true, value = "select count(*) from hddc_activefault where  province = :provinceName and city =:cityName and area =:areaName and is_valid='1'")
    Integer getCountByArea(String provinceName,String cityName,String areaName);
}
